package com.cqw.commontest.io;

import java.io.File;
import java.util.Arrays;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-04-20 11:32
 * @Description:
 */
public class FileTest {


    public static void main(String[] args) {
        File file = new File("D:\\fileTest");
        String[] list = file.list();
        //Arrays.stream(list).forEach(System.out::println);

        File[] files = file.listFiles();

        Arrays.stream(files).forEach(file1 -> {
//            System.out.println("文件名称：" + file1.getName());
//            System.out.println("文件最后修改时间：" + file1.lastModified());
//            System.out.println("文件大小：" + file1.length());
//            System.out.println("文件是否可读：" + file1.canRead());
//            System.out.println("文件是否可写：" + file1.canWrite());
            //System.out.println("是否是文件夹：" + file1.isDirectory());
//            System.out.println("====================================");
        });

        File file1 = new File("D:\\fileTest\\file\\file");

        if (!file1.exists()) {
            file1.mkdirs();
        }
        File[] files1 = file1.listFiles();
        //System.out.println(files1);

        getFileInfo(new File("D:\\fileTest"));
    }


    private static void getFileInfo(File file) {
        if (!file.exists()) {
            System.out.println("文件不存在");
        }

        File[] list = file.listFiles();
        for (File file1 : list) {
            if (file1.isDirectory()) {
                getFileInfo(file1);
            } else {
                System.out.println(file1.getAbsolutePath());
            }
        }
    }


}
